/*
 * @Author: 星孑
 * @Date: 2022-03-10 15:27:50
 * @LastEditors: 星孑
 * @LastEditTime: 2022-04-12 16:27:45
 * @FilePath: /vue-template-web/vue.config.js
 * @Description:打包配置文件
 */
const path = require('path')
// const Timestamp = new Date().getTime()

module.exports = {
  publicPath: './',
  chainWebpack: config => {
    config.resolve.alias // 为指定目录设置全局别名
      .set('@', path.join(__dirname, 'src'))
      .set('@public', path.join(__dirname, 'public'))
    config.module
      .rule('svg')
      .exclude.add(path.join(__dirname, 'src/icons'))
      .end()

    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(path.join(__dirname, 'src/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()
  },
  configureWebpack: config => {
  //  console.log('-------------- config: ', config)
    config.output = {
      path: path.resolve(__dirname, 'dist'),
      filename: `js/[name].[hash].js`,
      publicPath: '',
      chunkFilename: `js/[name].[hash].js`
    }
    config.optimization = {

      splitChunks: {
        chunks: 'all',
        minChunks: 1,
        cacheGroups: {
          vue: {
            name: 'vue',
            test: /[\\/]node_modules[\\/]vue[\\/]/,
            priority: -10
          },
          vuex: {
            name: 'vuex',
            test: /[\\/]node_modules[\\/]vuex[\\/]/,
            priority: -10
          },
          'vue-router': {
            name: 'router',
            test: /[\\/]node_modules[\\/]vue-router[\\/]/,
            priority: -10
          },
          'element-ui': {
            name: 'element-ui',
            test: /[\\/]node_modules[\\/]element-ui[\\/]/,
            priority: -10
          },
          vendors: {
            name: 'vendors',
            test: /[\\/]node_modules[\\/]/,
            priority: -20
          }
        }

      },
      runtimeChunk: {
        name: 'single'
      }
    }
  }
}
